package com.wuyan.locationdog.view

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter
import com.contrarywind.view.WheelView
import com.wuyan.locationdog.R
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.TranslationConfig


class DogAgePopup(context: Context, var sureCallback: (String) -> Unit) : BasePopupWindow(context) {


    init {
        contentView = createPopupById(R.layout.pop_dog_age)
        popupGravity = Gravity.BOTTOM
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        val yearlists = mutableListOf<String>()
        for (i in 0 until 20) {
            yearlists.add("${i}岁")
        }

        val lists = mutableListOf<String>()

        for (i in 0 until 12) {
            lists.add("${i}个月")
        }
        findViewById<View>(R.id.btnClose).setOnClickListener {
            dismiss()
        }
        findViewById<View>(R.id.btnSure).setOnClickListener {
            val yearIndex = findViewById<WheelView>(R.id.year).currentItem
            val monthIndex = findViewById<WheelView>(R.id.month).currentItem

            sureCallback.invoke(yearlists[yearIndex] + lists[monthIndex])

            dismiss()
        }
        findViewById<WheelView>(R.id.year).apply {

            adapter = ArrayWheelAdapter<String>(yearlists)
        }
        findViewById<WheelView>(R.id.month).apply {

            adapter = ArrayWheelAdapter<String>(lists)
        }
    }

    override fun onCreateShowAnimation(): Animation? {
        return AnimationHelper.asAnimation()
            .withTranslation(TranslationConfig.FROM_BOTTOM)
            .toShow()
    }

}
